import Vue from 'vue'
import Toast from './Toast.vue'

const ToastConstructor = Vue.extend(Toast);

function showToast(options) {
    const toastDOM = new ToastConstructor({
        el: document.createElement('div'),
        data() {
            return {
                text: options.text,
                duration: options.duration,
                show: true
            }
        }
    });

    document.body.appendChild(toastDOM.$el);

    setTimeout(() => {
        toastDOM.show = false;
    }, options.duration);
}

function toastRegistry() {
    Vue.prototype.$toast = showToast;
}

export default toastRegistry;